<?php
/**
 * WebProduction Shop (wpshop)
 * @copyright (C) 2011-2012 WebProduction (tm) <webproduction.com.ua>
 *
 * This program is commercial software;
 * you cannot redistribute it and/or modify it.
 */
PackageLoader::Get()->import('JSPrototype');
PackageLoader::Get()->import('JSScriptAculoUs');
PackageLoader::Get()->import('jQuery');
PackageLoader::Get()->import('jQueryUI');
PackageLoader::Get()->registerJSFile('/_js/no-conflict.js');
PackageLoader::Get()->registerJSFile('/_js/mouse.js');
PackageLoader::Get()->registerJSFile('/_js/jquery.lightbox-0.5.js');
PackageLoader::Get()->registerJSFile('/_js/jquery.cookie.js');
PackageLoader::Get()->registerJSFile('/_js/jQueryResolution.js');
PackageLoader::Get()->registerJSFile('/_js/p2q_embed_object.js');
PackageLoader::Get()->registerJSFile('/_js/swfobject.js');
PackageLoader::Get()->registerJSFile('/_js/jQueryToggler.js');
PackageLoader::Get()->registerJSFile('/_js/jQueryAjaxLoading.js');
PackageLoader::Get()->import('StringUtils');
PackageLoader::Get()->import('ImageProcessor');
PackageLoader::Get()->import('Checker');
PackageLoader::Get()->import('SQLObject2');
PackageLoader::Get()->import('MailUtils');
PackageLoader::Get()->import('ServiceUtils');
PackageLoader::Get()->import('DateTime');
PackageLoader::Get()->import('JSPlaceHolder');
PackageLoader::Get()->import('CKFinder');
PackageLoader::Get()->import('CommentsAPI');
PackageLoader::Get()->import('Forms');
PackageLoader::Get()->import('Stepper');


$wrapper = Stepper_Wrapper::Get('Default');
$wrapper->setParamValue('content_main_tpl_id', 'stepper-maintpl');
$wrapper->setParamValue('content_button_main_id', 'stepper-main');
$wrapper->setParamValue('content_button_prev_id', 'stepper-prev');
$wrapper->setParamValue('content_button_next_id', 'stepper-next');
$wrapper->setParamValue('content_button_first_id', 'stepper-first');
$wrapper->setParamValue('content_button_last_id', 'stepper-last');
$wrapper->setParamValue('setting_object_count_on_page', 10);
$wrapper->setParamValue('setting_visible_buttons_count', 11);
$wrapper->setParamValue('setting_current_page_position', 6);

MailUtils_Config::Get()->setSender(new MailUtils_SenderQueDB());
try {
    Engine::GetCache()->setStorage(
        Storage::Initialize('EngineCache', new Storage_HandlerMemcache('triumph-'))
    );
} catch (Exception $e) {

}

if (PackageLoader::Get()->getMode('debug')) {
    PackageLoader::Get()->import('EngineDebug', true);
}

if (PackageLoader::Get()->getMode('development')) {
    // отключаем кешироание вообще
    Engine::GetCache()->disableCache();

    // задаем конфигурацию SQLObject'у
    SQLObjectConfig::Get()->setPathDatabaseClasses(PROJECT_PATH.'api/db/');

    $table = SQLObjectConfig::Get()->addTable('user', 'XUser');
    $table->addField('id', 'int(11)', 'auto_increment');
    $table->addKey('id', 'primary');
    $table->addField('name', 'varchar(32)');
    $table->addField('login', 'varchar(32)');
    $table->addField('level', 'int(11)');
    $table->addField('password', 'varchar(32)');
    $table->addField('bday', 'date');
    $table->addField('cdate', 'datetime');
    $table->addField('adate', 'datetime');
    $table->addField('sdate', 'datetime');
    $table->addField('phone', 'varchar(32)');
    $table->addField('email', 'varchar(32)');
    $table->addField('image', 'varchar(100)');
    $table->addField('ip', 'varchar(100)');
    $table->addField('sid', 'varchar(100)');
    $table->addField('sudoid', 'int(11)');

    $table = SQLObjectConfig::Get()->addTable('useracl', 'XUserACL');
    $table->addField('id', 'int(11)', 'auto_increment');
    $table->addKey('id', 'primary');
    $table->addField('userid', 'int(11)');
    $table->addField('acl', 'varchar(255)');

    $table = SQLObjectConfig::Get()->addTable('photoalbum', 'XPhotoalbum');
    $table->addField('id', 'int(11)', 'auto_increment');
    $table->addKey('id', 'primary');
    $table->addField('image', 'varchar(200)');
    $table->addField('name', 'varchar(100)');
    $table->addField('cdate', 'datetime');
    $table->addField('description', 'text');
    $table->addField('count', 'int(11)');
    $table->addField('hidden', 'tinyint(1)');
    $table->addField('main', 'tinyint(1)');

    $table = SQLObjectConfig::Get()->addTable('photo', 'XPhoto');
    $table->addField('id', 'int(11)', 'auto_increment');
    $table->addKey('id', 'primary');
    $table->addField('image', 'varchar(200)');
    $table->addField('name', 'varchar(100)');
    $table->addField('cdate', 'datetime');
    $table->addField('photoalbumid', 'int(11)');
    $table->addField('description', 'text');
    $table->addField('hidden', 'tinyint(1)');

    // выполняем SQLObject Sync
    SQLObjectConfig::Get()->sync();

    // выполяем Engine pages generator
    Engine::GetGenerator()->process();
}

PackageLoader::Get()->registerPHPDirectory(dirname(__FILE__).'/db/');
PackageLoader::Get()->registerPHPDirectory(dirname(__FILE__).'/services/');
PackageLoader::Get()->registerPHPDirectory(dirname(__FILE__).'/system/');
PackageLoader::Get()->registerPHPDirectory(dirname(__FILE__).'/forms/');
PackageLoader::Get()->registerPHPDirectory(dirname(__FILE__).'/acl/');

// регистрируем сервисы
ServiceUtils::Get()->registerService('Triumph');
ServiceUtils::Get()->registerService('Triumph_UserService');
ServiceUtils::Get()->registerService('Triumph_MediaService');


if (PackageLoader::Get()->getMode('development')) {

        

}

SQLObjectConfig::Get()->setMaxPoolObjects('User', 100);
Engine::GetEvents()->observe(
'afterQueryDefine',
new Shop_AuthMachine()
);

Engine_Auth::SetAuthService(Triumph::Get()->getUserService());

Engine::getEvents()->observe(
'beforeContentProcess',
new Shop_ACLObserver()
);

// задаем собственный URLParser
//Engine::Get()->setURLParser(Shop_URLParser::Get());

//Engine::GetCache()->registerModifier(new BC_CacheModifierCity());

PackageLoader::Get()->registerCSSDataProcessor(new Shop_CSSDataProcessor());

// Задаем соль для шифрования пароля.
// Соль не должна меняться, поскольку не кто потом не зайдёт в систему
// желательное значение соли это названия проекта
// Например: WebProduction
// если соль false то шифрование производится md5()
//BC::Get()->getUserService()->setPasswordSalt('WebProduction');


